<?php
/**
 * User Model
 *
 * PHP versions 4 and 5
 *
 * Infectamic: Free online role playing game, easily playable by browser. (http://infectamic.goldzoneweb.info)
 * Copyright 2011, Loic Chardonnet
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright     Copyright 2011, Loic Chardonnet
 * @link          http://infectamic.goldzoneweb.info Infectamic
 * @package       cake
 * @subpackage    cake.cake.libs.controller
 * @since         CakePHP(tm) v 0.2.9
 * @license       MIT License (http://www.opensource.org/licenses/mit-license.php)
 */
class User extends AppModel {
	var $name = 'User';
	var $displayField = 'username';
	var $validate = array(
		'username' => array(
			'notempty' => array(
				'rule' => array('notempty'),
				'message' => 'You must give a username!',
				'allowEmpty' => false,
				'required' => true,
				'last' => false, // Stop validation after this rule
				'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
			'alphanumeric' => array(
				'rule' => array('alphanumeric'),
				'message' => 'You must give an alpha numerical value!',
				'allowEmpty' => false,
				'required' => true,
				'last' => false, // Stop validation after this rule
				'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
			'maxlength' => array(
				'rule' => array('maxlength', 255),
				'message' => 'You must give a username shorter than 255 characters!',
				'allowEmpty' => false,
				'required' => true,
				'last' => false, // Stop validation after this rule
				'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
			'minlength' => array(
				'rule' => array('minlength', 2),
				'message' => 'You must give a username longer than 2 characters!',
				'allowEmpty' => false,
				'required' => true,
				'last' => false, // Stop validation after this rule
				'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
		'password' => array(
			'notempty' => array(
				'rule' => array('notempty'),
				'message' => 'You must give a password!',
				'allowEmpty' => false,
				'required' => true,
				'last' => false, // Stop validation after this rule
				'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
			'alphanumeric' => array(
				'rule' => array('alphanumeric'),
				'message' => 'You must give an alpha numerical value!',
				'allowEmpty' => false,
				'required' => true,
				'last' => false, // Stop validation after this rule
				'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
			'maxlength' => array(
				'rule' => array('maxlength', 255),
				'message' => 'You must give a password shorter than 255 characters!',
				'allowEmpty' => false,
				'required' => true,
				'last' => false, // Stop validation after this rule
				'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
			'minlength' => array(
				'rule' => array('minlength', 2),
				'message' => 'You must give a password longer than 2 characters!',
				'allowEmpty' => false,
				'required' => true,
				'last' => false, // Stop validation after this rule
				'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
	);
	//The Associations below have been created with all possible keys, those that are not needed can be removed

	var $belongsTo = array(
		'Design' => array(
			'className' => 'Design',
			'foreignKey' => 'design_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		),
		'Team' => array(
			'className' => 'Team',
			'foreignKey' => 'team_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		),
		'Nap' => array(
			'className' => 'Nap',
			'foreignKey' => 'nap_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		),
		'Group' => array(
			'className' => 'Group',
			'foreignKey' => 'group_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		)
	);

	var $hasMany = array(
		'Street' => array(
			'className' => 'Street',
			'foreignKey' => 'user_id',
			'dependent' => false,
			'conditions' => '',
			'fields' => '',
			'order' => '',
			'limit' => '',
			'offset' => '',
			'exclusive' => '',
			'finderQuery' => '',
			'counterQuery' => ''
		)
	);

        /**
         * Returns initial data.
         * @return <array> what create will return.
         */
        function getInitialData() {
            $data['group_id']       = $this->Group->findByName('Infected');
            $data['group_id']       = $data['group_id']['Group']['id'];
            $data['design_id']      = $this->Design->findByName('dop');
            $data['design_id']      = $data['design_id']['Design']['id'];
            $data['has_help']       = true;
            $data['has_image']      = true;
            $data['has_js']         = true;
            $data['health']         = 0;
            $data['metabolism_1']   = 1;
            $data['metabolism_2']   = 1;
            $data['metabolism_3']   = 1;
            $data['metabolism_4']   = 1;
            $data['technique_1']    = 1;
            $data['technique_2']    = 1;
            $data['technique_3']    = 1;
            $data['technique_4']    = 1;
            $data['attack_1']       = 0;
            $data['attack_2']       = 0;
            $data['attack_3']       = 0;
            $data['attack_4']       = 0;
            $data['total_socre']    = 0;
            $data['current_score']  = 0;
            $data['rebirthday']     = date('Y-m-d H:i:s');
            return ($data);
        }
}
?>